define(['../../carrys/cityList','../../carrys/jsonList','../../../../js/lib/other/sweet-alert'],function(cityData,jsonList,sweetAlert) {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','55');//显示底部文字

		/*
		* [{"name":"金融纠纷","sel":false,"val":"1"},
			{"name":"民间借贷纠纷","sel":false,"val":"2"},
			{"name":"破产清算","sel":false,"val":"3"},
			{"name":"担保纠纷","sel":false,"val":"4"},
			{"name":"合同纠纷","sel":false,"val":"5"},
			{"name":"知识产权纠纷","sel":false,"val":"6"},
			{"name":"侵权纠纷","sel":false,"val":"7"},
			{"name":"强制执行","sel":false,"val":"8"},
			{"name":"其他","sel":false,"val":"9"}
			]
		* */
    	$scope.isslide_up = false;//默认擅长领域
    	var caseTypeList = transData.storage_baseData.queryAdvFieldList.advFieldList;
        caseTypeList.forEach(function(e){
        	e.caseTypeName = e.advFieldName;
        	e.caseTypeId = e.advFieldId;
            e.sel = false;
        });
    	var goodFieldNum;
    	//默认值
    	$scope.jsonList = jsonList;
    	$scope.applyUserTypeList =  [{'name':'个人','val':'0'},
    	     			            {'name':'机构','val':'1'}
    	    			         ];
    	$scope.agencySizeTypeList =  [{'name':'1-10人','val':'1'},
     	     			            {'name':'10-30人','val':'2'},
     	    			            {'name':'30-50人','val':'3'},
     	    			            {'name':'50-100人','val':'4'},
     	    			            {'name':'100人以上','val':'5'}
     	    			         ];
    	$scope.companyTypeList =  [{'name':'个人所'},
     	     			            {'name':'合伙制'},
     	    			            {'name':'合资所'}
     	    			         ];
    	$scope.voucherTypeList =  [{'name':'身份证','val':'1'},
     	     			            {'name':'职业许可证','val':'2'}
     	    			         ];
     	
    	$scope.mobileNo = "";
    	$scope.userName = "";
    	$scope.idType = "2";
    	$scope.idNo = "";
    	$scope.applyUserType = "1";
    	$scope.goodField = "";
    	$scope.provinceName = "",$scope.cityName ="";
    	$scope.charger = "";
    	$scope.linkman = "";
    	$scope.agencySize = "1-10人";
    	$scope.companyType = "个人所";
    	$scope.branch ="";
    	$scope.idTypeDesc = "执业许可证";
    	
    	/*$scope.$watch('applyUserType', function() {
    		if($scope.applyUserType == '0'){
    			$scope.idType = "1";
    			$scope.idTypeDesc = "身份证";
    		}else if($scope.applyUserType == '1'){
    			$scope.idType = "2";
    			$scope.idTypeDesc = "执业许可证";
    		}
		});*/
    	
    	//整理省市数据
    	var provinceList = new Array();
    	var cityListTemp = new Array();
    	var districtTemp = new Array();
    	$scope.keyword = "",$scope.provinceName = "",$scope.cityName ="",$scope.districtName = "";
    	$scope.provinceName1 = "",$scope.cityName1 ="",$scope.districtName1 = "";
    	$scope.provinceName2 = "",$scope.cityName2 ="",$scope.districtName2 = "";
    	
    	
		collateData();//整理列表数据
		//显示省份
    	$scope.provinceData = provinceList;
    	//显示城市
    	$scope.clickCity = function(data,flag){
    		var cityList = new Array();
    		var provinceName = data.province;
    		for(var i=0;i<cityListTemp.length;i++){
    			if(cityListTemp[i].province == provinceName){
    				var tempData = {'city': cityListTemp[i].city};
    				cityList.push(tempData);
    			}
    		}
    		if(flag === '0'){
    			$scope.cityData = cityList;
    		}else if(flag === '1'){
    			$scope.cityData1 = cityList;
    		}else if(flag === '2'){
    			$scope.cityData2 = cityList;
    		}
    		
    	}
    	//显示地区
    	$scope.clickArea = function(data,flag) {
    		var districtList = new Array();
    		var districtList1 = new Array();
    		var cityName = data.city;
    		for(var i=0;i<districtTemp.length;i++){
    			if(districtTemp[i].city == cityName){
    				districtList = districtTemp[i].district;
    				break;
    			}
    		}
    		for(var i=0;i< districtList.length;i++){
    			var tempData = {'district':districtList[i]};
    			districtList1.push(tempData);
    		}
    		if(flag === '0'){
    			$scope.districtData = districtList1;
    		}else if(flag === '1'){
    			$scope.districtData1 = districtList1;
    		}else if(flag === '2'){
    			$scope.districtData2 = districtList1;
    		}
    		
    	}

		$scope.scrollToTop=function(ele){
            if(_YTG_IOSorANDROID.systemJudge()==='Android'){
                console.log(ele,document.querySelector(ele).offsetTop)
                var offsetTop=document.querySelector(ele).offsetTop;
                if(offsetTop){
                    _fire_eleSorollToTarget('#complete_material .box2',offsetTop-54,300)
                }
            }
		}
		
    	//点击显示擅长领域
    	$scope.showField = function(){
    		$scope.isslide_up = true;
    		$scope.caseTypeList = caseTypeList;
    	}
    	
    	//点击关闭擅长领域
    	$scope.closeType = function(){
    		$scope.isslide_up = false;
    	}
    	
    	//选择案件类型
    	$scope.selectType = function(flag){
    		var num=0;
            for(var i=0;i<caseTypeList.length;i++){
                if(caseTypeList[i].sel){
                    num++
                }
            }
			if(caseTypeList[flag].sel){
				caseTypeList[flag].sel = false;
			}else{
                if(num<4){
                    caseTypeList[flag].sel = true;
				}
			}

    	}
    	
    	//确认选择
    	$scope.confirmBtn = function(){
			var tempString = "",tempFieldString = "";
			for(var i=0;i<caseTypeList.length;i++){
				if(caseTypeList[i].sel){
					tempString = tempString + caseTypeList[i].caseTypeName + "_";
					tempFieldString = tempFieldString + caseTypeList[i].caseTypeId + ",";
				}
			}
			$scope.goodField = tempString.substring(0,tempString.length-1);
			goodFieldNum = tempFieldString.substring(0,tempFieldString.length-1);
    		$scope.isslide_up = false;
    	}
    	
    	
    	//点击提交
        $scope.subConfirm = function(){
        	var reg = new RegExp("^[0-9]*$");
        	if(! $scope.lawfirmName){
    			$scope.$emit("promptAlertMsg","律所名称不能为空");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if(! $scope.lawfirmType){
    			$scope.$emit("promptAlertMsg","请选择律所类型");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if(! $scope.idType){
    			$scope.$emit("promptAlertMsg","请选择证件类型");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if(! $scope.idNo){
    			$scope.$emit("promptAlertMsg","证件号码不能为空");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if($scope.idType == '1' && !_YHC_util.IdentityCodeValid($scope.idNo)){
				$scope.$emit("promptAlertMsg","无效身份证号");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
			}else if($scope.idType == '2' && ! reg.test($scope.idNo)){
				$scope.$emit("promptAlertMsg","无效执业许可证号");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
			}else if(! $scope.provinceName){
    			$scope.$emit("promptAlertMsg","请选择地区");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if(! $scope.charger){
    			$scope.$emit("promptAlertMsg","请选择负责人");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if(! $scope.linkman){
    			$scope.$emit("promptAlertMsg","请选择联系人");
        		$scope.$emit("showCollect",true);
        		$timeout(function(){
        			$scope.$emit("showCollect",false);
        		},transData.promptTime);
                return;
    		}else if(! $scope.mobileNo){
                $scope.$emit("promptAlertMsg","手机号不能为空");
                $scope.$emit("showCollect",true);
                $timeout(function(){
                    $scope.$emit("showCollect",false);
                },transData.promptTime);
                return;
            }else if(! _SYT_util.isValidNo($scope.mobileNo)){
                $scope.$emit("promptAlertMsg","手机号不正确");
                $scope.$emit("showCollect",true);
                $timeout(function(){
                    $scope.$emit("showCollect",false);
                },transData.promptTime);
                return;
            }else{
    			subLsData();
    		}
        }
        
      //调用代理提交
        function subLsData(){
        	var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	try{
            	bizInfo.province = ($scope.provinceName).province;
            	bizInfo.city = ($scope.cityName).city?($scope.cityName).city:'';
            	bizInfo.county =  ($scope.districtName).district?($scope.districtName).district:'';
            	
        	}catch(e){
                bizInfo.province = '';
                bizInfo.city = '';
                bizInfo.county =  '';
        	}
        	bizInfo.mobileNo = $scope.mobileNo;
        	bizInfo.lawfirmName = $scope.lawfirmName;
        	bizInfo.idType = $scope.idType;
        	bizInfo.idNo = $scope.idNo;
        	bizInfo.lawfirmType = $scope.lawfirmType;

        	bizInfo.charger = $scope.charger;
        	bizInfo.linkman = $scope.linkman;
        	bizInfo.lawfirmSize = $scope.agencySize;
        	bizInfo.website = $scope.agencySize;
        	// bizInfo.companyType = $scope.companyType;
        	// bizInfo.branch = $scope.branch;
        	bizInfo.advField = goodFieldNum;
        	console.log(bizInfo)
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("lawfirmApply",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
						console.log(bizInfo)
		    			$timeout(function(){
		    				$scope.$emit("loadingChange",false);
		    				FIREFLY("提交成功", "我方会在3个工作日内审核完毕","",function(){
    							$timeout(function(){
    								history.back();
    							},0);
		    				});
						},0);
		    		},function(data){
    					console.log(data)
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("loadingChange",false);
								$scope.$emit("promptAlertMsg",data.errorMsg);
				    			$scope.$emit("showCollect",true);
				    			$timeout(function(){
				    				$scope.$emit("showCollect",false);
				    				$scope.$emit("goNext","/mineLs");
				    			},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit("loadingChange",false);
							$scope.$emit("promptAlertMsg","连接超时");
			    			$scope.$emit("showCollect",true);
			    			$timeout(function(){
			    				$scope.$emit("showCollect",false);
			    				$scope.$emit("goNext","/mineLs");
			    			},transData.promptTime);
		    			}
		    		});
        }
        
//    	//监听跳过点击事件
//    	$scope.$on('skipEvent', function(event,data){
//    		if(data){
//    			$scope.$emit("goNext","/minePt");
//    		}
//        });
    	
    	
		
		//整理省份数据
    	function collateData() {
    		cityListTemp = new Array();
    		districtTemp = new Array();
			for(var key in cityData.addressDetail){
				var tempData = {"province":key};
				provinceList.push(tempData);
				collateCity(key,cityData.addressDetail[key]);
			}
    	}
    	//整理城市数据
		function collateCity(data1,data2) {
			for(var key in data2){
				var tempList = {'province':data1,'city': key};
				cityListTemp.push(tempList);
				districtCity(key,data2[key]);
			}
		}
		//整理县区数据
		function districtCity(data1,data2){
			var tempList = {'city': data1,'district': data2};
			districtTemp.push(tempList);
		}
        $scope.$apply();
    }];
});